﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssetStudio
{
    public class AssetInfo
    {
        public int preloadIndex;
        public int preloadSize;
        public PPtr<Object> asset;

        public AssetInfo(ObjectReader reader)
        {
            preloadIndex = reader.ReadInt32();
            preloadSize = reader.ReadInt32();
            asset = new PPtr<Object>(reader);
        }
    }

    //AB 结构 PreloadTable + Container
    //Chunk 压缩可以随机读取 Stream压缩 Audio 只能顺序读取
    //依赖之类的不再读取了
    //后面还有属性但是没有读取了
    public sealed class AssetBundle : NamedObject
    {
        public PPtr<Object>[] m_PreloadTable;
        public KeyValuePair<string, AssetInfo>[] m_Container;
        public bool m_IsStreamedSceneAssetBundle;

        public AssetBundle(ObjectReader reader) : base(reader)
        {
            var m_PreloadTableSize = reader.ReadInt32();
            m_PreloadTable = new PPtr<Object>[m_PreloadTableSize];
            for (int i = 0; i < m_PreloadTableSize; i++)
            {
                m_PreloadTable[i] = new PPtr<Object>(reader);
            }

            var m_ContainerSize = reader.ReadInt32();
            m_Container = new KeyValuePair<string, AssetInfo>[m_ContainerSize];
            for (int i = 0; i < m_ContainerSize; i++)
            {
                m_Container[i] = new KeyValuePair<string, AssetInfo>(reader.ReadAlignedString(), new AssetInfo(reader));
            }

            //reader.ReadInt32();
            //reader.ReadInt32();
            //var asset = new PPtr<Object>(reader);
            //reader.ReadUInt32();
            //reader.ReadAlignedString();
            //var depNum = reader.ReadInt32();
            //for(var i=0; i < depNum; i++)
            //{
            //    reader.ReadAlignedString();
            //}
            ////找到所有StreamScene的Bundle
            //m_IsStreamedSceneAssetBundle = reader.ReadBoolean();
        }
    }
}
